import React from 'react'
import { Row, Col, Form, Input, Button, message } from 'antd'
import { connect } from 'dva'
import router from 'umi/router';
import styles from './index.less'

@connect(({ home, loading, user }) => ({
  home,
  loading,
  user
}))

class Index extends React.Component {
  

  state = {

  }

  componentDidMount() {

  }

  handleLogin = () => {
    const {
      dispatch,
      form: { getFieldsValue }
    } = this.props
    const { ac, pw } = getFieldsValue()


    dispatch({
      type: 'user/login',
      payload: {
        accout: ac,
        password: pw
      }
    }).then(res => {
      if (res.Status === 1) {
        message.success('登录成功')
        router.push('/dashboard/analysis')
      } else {
        message.error('登录失败')
      }
    })
  }

  render() {

    const {
      form: { getFieldDecorator }
    } = this.props

    return (
      
      <div className={styles.login}>
        <Row gutter={0} type="flex" justify="center" align="middle">
          <Col>
            <div >
              <div className={styles.title1}>企业信息管理系统</div>
              <div>
                <Row gutter={40} type="flex" align="middle">
                  <Col>
                    <span className={styles.title2}>账 号:</span>
                  </Col>
                  <Col>
                    {getFieldDecorator('ac', {
                      // initialValue: 1,
                      rules: [{ required: true, message: '请输入' }],
                    })(
                      <Input style={{ width: 250 }} placeholder="请输入账号" />
                    )}

                  </Col>
                </Row>
                <Row gutter={40} style={{ marginTop: 20 }} type="flex" align="middle">
                  <Col>
                    <span className={styles.title2}>密 码:</span>
                  </Col>
                  <Col>
                    {getFieldDecorator('pw', {
                      // initialValue: 1,
                      rules: [{ required: true, message: '请输入' }],
                    })(
                      <Input.Password style={{ width: 250 }} placeholder="请输入密码" />
                    )}
                  </Col>
                </Row>
              </div>
              <div style={{ width: 350, marginTop: '20%' }}>
                <Button block type="primary" size="large" onClick={this.handleLogin}>登陆</Button>
              </div>
            </div>
          </Col>
        </Row>
      </div>
    )
  }
}

export default Form.create()(Index)  